<?php
/* variables will be used in smarty template */
$this->view->assign('APP_ID', APP_ID);
$this->view->assign('APP_KEY', APP_KEY);

$this->view->assign("OAUTH_TYPE_QQ", OAUTH_TYPE_QQ);
$this->view->assign("OAUTH_TYPE_KAIXIN", OAUTH_TYPE_KAIXIN);
$this->view->assign("OAUTH_TYPE_WEIBO", OAUTH_TYPE_WEIBO);
$this->view->assign("OAUTH_TYPE_RENREN", OAUTH_TYPE_RENREN);

$this->view->assign('OAUTH_QQ_APP_KEY', OAUTH_QQ_APP_KEY);
$this->view->assign('OAUTH_QQ_SECRET_KEY', OAUTH_QQ_SECRET_KEY);
$this->view->assign('OAUTH_QQ_REDIRECT_URI', OAUTH_QQ_REDIRECT_URI);
$this->view->assign('OAUTH_SINA_APP_KEY', OAUTH_SINA_APP_KEY);
$this->view->assign('OAUTH_SINA_SECRET_KEY', OAUTH_SINA_SECRET_KEY);
$this->view->assign('OAUTH_SINA_REDIRECT_URI', OAUTH_SINA_REDIRECT_URI);
$this->view->assign('OAUTH_KAIXIN_APP_KEY', OAUTH_KAIXIN_APP_KEY);
$this->view->assign('OAUTH_KAIXIN_SECRET_KEY', OAUTH_KAIXIN_SECRET_KEY);
$this->view->assign('OAUTH_KAIXIN_REDIRECT_URI', OAUTH_KAIXIN_REDIRECT_URI);
$this->view->assign('OAUTH_RENREN_APP_KEY', OAUTH_RENREN_APP_KEY);
$this->view->assign('OAUTH_RENREN_SECRET_KEY', OAUTH_RENREN_SECRET_KEY);
$this->view->assign('OAUTH_RENREN_REDIRECT_URI', OAUTH_RENREN_REDIRECT_URI);

$this->view->assign('WebRoot',WebRoot);
$this->view->assign('WebUrl',WebUrl);
$this->view->assign('IMG_DIR', IMG_DIR);
$this->view->assign('CSS_DIR', CSS_DIR);
$this->view->assign('JS_DIR', JS_DIR);
$this->view->assign("DOMAIN", DOMAIN);
$this->view->assign("ModuleAction", ModuleAction);
$this->view->assign("MethodAction", MethodAction);
$this->view->assign("FIRST_TITLE", FIRST_TITLE);
$this->view->assign("SECOND_TITLE", SECOND_TITLE);

$this->view->assign("FAMILY_OPEN_PUBLIC", "public");
$this->view->assign("FAMILY_OPEN_PROTECT", "protect");
$this->view->assign("FAMILY_OPEN_PRIVATE", "private");

$this->view->assign("RESOURCE_STATE_INIT", "init");
$this->view->assign("RESOURCE_STATE_DELETED", "deleted");

$this->view->assign("CONTENT_TYPE_FAMILY", "family");
$this->view->assign("CONTENT_TYPE_USER", "user");
$this->view->assign("CONTENT_TYPE_RELATION", "relation");
$this->view->assign("CONTENT_TYPE_EVENT", "event");
$this->view->assign("CONTENT_TYPE_PHOTO", "photo");
$this->view->assign("OPERATE_TYPE_ADD", "add");
$this->view->assign("OPERATE_TYPE_EDIT", "edit");
$this->view->assign("OPERATE_TYPE_DELETE", "delete");
$this->view->assign("OPERATE_TYPE_RESTORE", "restore");

$this->view->assign("MALE", MALE);
$this->view->assign("FEMALE", FEMALE);

$this->view->assign("CACHE_HINT", CACHE_HINT);

$this->view->assign("ACTIVE_PEOPLE_PAGE", ACTIVE_PEOPLE_PAGE);
$this->view->assign("ACTIVE_PEOPLE_PATH", ACTIVE_PEOPLE_PATH);

$this->view->assign("PHOTO_WALL_URL", PHOTO_WALL_URL);
$this->view->assign("PHOTO_WALL_PATH", PHOTO_WALL_PATH);

$this->view->assign("SURNAMES_HTML", SURNAMES_HTML);
$this->view->assign("SURNAMES_PATH", SURNAMES_PATH);

$this->view->assign("LATEST_PEOPLE_HTML", LATEST_PEOPLE_HTML);
$this->view->assign("LATEST_PEOPLE_PATH", LATEST_PEOPLE_PATH);

$path = M_Tools::create_crumbs_path("/".ModuleAction."/".MethodAction);

$paras = array();
$replace = array();
if(isset($_REQUEST['userid']) && $_REQUEST['userid'])
  {
    $userid = $_REQUEST['userid'];
    $db = new M_qin_users();
    $user = $db->get($userid);
    if (!$user["id"])
      die("user not exists with id $userid");
    $surname_id = M_Tools::get_surname_id($user["first_name"]);
    $replace[] = "#user#";
    $replace[] = "#userid#";
    $replace[] =  "#surname#";
    $replace[] = "#surnameid#";
    $paras[] = $user["realname"];
    $paras[] = $userid;
    $paras[] = $user["first_name"];
    $paras[] = $surname_id;

    /* for return surname link in home page */
    $this->view->assign("surnameid", $surname_id);
    $this->view->assign("surname", $user["first_name"]);

    /* add affiliate */
    $affiliate_file = AFFILIATE_PATH."/".$userid.".html";
    if (file_exists($affiliate_file))
      $this->view->assign("affiliate_file", $affiliate_file);
  }
if(isset($_REQUEST['surname']) && $_REQUEST['surname'])
  {
    $surname_id = $_REQUEST['surname'];
    $surnames = M_Tools::get_all_surnames();
    $surname = array_search($surname_id, $surnames);
    $replace[] = "#surname#";
    $replace[] = "#surnameid#";
    $paras[] = $surname;
    $paras[] = $surname_id;
}
$replaced_path = array();
foreach($path as $step)
  {
    $replaced_path[] = str_replace($replace, $paras, $step);
  }
$this->view->assign("meta", end($replaced_path));
$this->view->assign("crumbs", $replaced_path);

$this->view->assign("SURNAMES_PER_LINE", SURNAMES_PER_LINE);
$this->view->assign("session", $_SESSION);
$this->view->assign("DEFAULT_USER_IN_HOME", DEFAULT_USER_IN_HOME);

$this->view->assign("rel_types", array(FATHER=>"爸爸",
				       MOTHER=>"妈妈",
				       WIFE=>"妻子",
				       HUSBAND=>"丈夫",
				       SON=>"儿子",
				       DAUGHTER=>"女儿"));
$this->view->assign("STATE", array(RESOURCE_STATE_INIT=>"正常",
				   RESOURCE_STATE_DELETED=>"已删除"));

/* debug flag */
$debug = (isset($_REQUEST['debug']) && $_REQUEST['debug']) ? 1 : 0;
$this->view->assign("debug", $debug);